package org.xsk.network.tcp.object;

import java.io.*;
import java.net.Socket;

/**
 * description: 客户端
 * <p>
 * date: 2021/6/10 12:59
 * author: x-one
 */
public class LoginClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 8000);
        // 发送请求
        OutputStream os = socket.getOutputStream();
        ObjectOutputStream oos =new ObjectOutputStream(os);
        User user =new User("Jack", "123456");
        oos.writeObject(user);

        // 读回应
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String replu = null;
        while ((replu = br.readLine()) != null) {
            System.out.println("我是客户端，服务器说：" + replu);
        }

        os.close();
        oos.close();
        socket.close();
    }
}
